class Solution {
public:
    vector<int> pathInZigZagTree(int label) {
        vector<int> ret;
        int ans = label;
        for(int i = 1;;i++){
            ret.push_back(ans);
            ans /= 2;
            if(pow(2,i)-1 >= label){
                break;
            }
        }
        
        reverse(ret.begin(),ret.end());
        int index = ret.size() % 2;
        
        for(int i = 0;i < ret.size();i++){
            if(i % 2 == index){
                int l = pow(2,i);
                int r = pow(2,i+1)-1;
                ret[i] = r - (ret[i]-l);
            }
        }
        return ret;
    }
};
